import { useState } from "react"

import http from "../../../helper/request"
import { IDetailResponse, IQueryDetailParams, IRecordMember, IResponseItem } from "./types"

const useApi = () => {
	const [loading, setLoading] = useState(false)

	async function generalHttp<T>(url: string, body: object | undefined, config: object = {}) {
		setLoading(true)
		let ret = await http.post<T>(url, body, config)
		setLoading(false)
		return ret
	}

	const getProxyDetailQueryDetail = (body?: IQueryDetailParams) =>
		generalHttp<IResponseItem<IDetailResponse>>("/proxyDetail/queryDetail", body)

	const rebateRateMemberList = (body?: object) =>
		generalHttp<Business.TableResourceType<IRecordMember>>("/rebateRate/memberList", body)

	const memberListAPI = (body?: object) => generalHttp("/member/queryMemberLs", body)

	return {
		loading,
		getProxyDetailQueryDetail,
		generalHttp,
		rebateRateMemberList,
		memberListAPI
	}
}

export default useApi
